package com.zhairuihao.admin;

import com.alibaba.druid.util.StringUtils;
import com.jfinal.core.Controller;
import com.jfinal.kit.HashKit;

import javax.servlet.http.HttpSession;

/**
 * 本 demo 仅表达最为粗浅的 jfinal 用法，更为有价值的实用的企业级用法 详见 JFinal 俱乐部: http://jfinal.com/club
 *
 * <p>IndexController
 */
public class LoginController extends Controller {

    public static String ADMIN_TOKEN = "ADMIN_TOKEN";
    private static final String ADMIN_USER = "3e44107170a520582ade522fa73c1d15";

    public void index() {
        String username = getPara("username");
        String pwd = getPara("password");
        if (StringUtils.isEmpty(pwd) && ADMIN_USER.equals(HashKit.md5(username))) {
            ADMIN_TOKEN = System.currentTimeMillis() + "";
            HttpSession session = getSession();
            session.setAttribute("token", ADMIN_TOKEN);
            redirect("/");
            return;
        }
        setAttr("errMsg", "登陆失败");
        setAttr("state", "fail");
        render("/login.html");
    }


}
